#include "player.h"
#include "TextureManager.h"

#define PI 3.1415926535f
namespace NOEXIT
{
	Player::Player():
		m_pos(512,1,512),
		m_sync_pos(512,1,512),
		m_dir(0,0,-1),
		m_rotation(0,0,0),
		m_velocity(0,0,0),
		info(-1)
	{
		

		playerId = -1;
		health = 1;
		state = normal;

		pRO = new RenderObject();

	}

	Player::~Player()
	{
		delete pRO;
	}

	void Player::applyImpulse(const vec3f& impulse)
	{
		m_rot_mat= Matrix3f::fromEulerAngles( m_rotation.x  , m_rotation.y , m_rotation.z  );
		vec3f worldSpaceImpulse = impulse ;
		m_velocity += worldSpaceImpulse;
		//hack?
		m_dir = Matrix3f::fromEulerAngles( m_rotation.x  , -m_rotation.y , m_rotation.z  ) * vec3f(0,0,-1);
	}

	void Player::rotate(const vec3f& change)
	{
		m_rotation +=  change * ( PI / 180 );
	}

	void Player::updatePos()
	{
		m_velocity -= m_velocity * 0.1f;
		//m_sync_pos += m_velocity;
		m_pos += m_velocity;

		m_pos_mat = Matrix4f(m_rot_mat);
		m_pos_mat[12] = m_pos[0];
		m_pos_mat[13] = m_pos[1];
		m_pos_mat[14] = m_pos[2];

	}

	void Player::setPlayerId(int i)
	{
		playerId = i;
		info.playerId = i;;
	}

 
}